/**
 * @author 秦易达
 *
 */
package com.lmx.repoDomain.tmodel;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import com.lmx.repoDomain.tmodel.business.User;//huibati;

import io.katharsis.resource.annotations.JsonApiIncludeByDefault;
import io.katharsis.resource.annotations.JsonApiResource;
import io.katharsis.resource.annotations.JsonApiToMany;
import io.katharsis.resource.annotations.JsonApiToOne;

/**
 * 工单表
 */
@Entity
@Table(name = "ccd_workorder")
@JsonApiResource(type = "workorder")
//@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler"})
public class Workorder extends BaseEntity {
	private String code; // 工单编码
	private String title; // 工单标题
	private Short type; // 类型
	private String desc; // 描述信息
	private Short isSuccess;// 成单状态
	private String freezeReason;//冻结原因
	private Customer customer;//对应客户
	private Task task;//对应任务
	private User creater;//创建人
	private Integer followTime;//跟进时间
	private User header;// 负责人
	private Set<User> concerned;// 关注人
	private Integer tbcTime;//待确认时间
	private Integer completeTime; // 成单
	private Integer createTime;//创建时间
	private Integer updateTime;// 更新时间
	private String remark;//备注

	@Column(name = "code")
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	@Column(name = "title")
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Column(name = "type")
	public Short getType() {
		return type;
	}

	public void setType(Short type) {
		this.type = type;
	}

	@Column(name = "descr")
	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	@Column(name = "is_success")
	public Short getIsSuccess() {
		return isSuccess;
	}

	public void setIsSuccess(Short isSuccess) {
		this.isSuccess = isSuccess;
	}

	@Column(name = "freeze_reason")
	public String getFreezeReason() {
		return freezeReason;
	}

	public void setFreezeReason(String freezeReason) {
		this.freezeReason = freezeReason;
	}

	@JsonApiToOne
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "customer_id",foreignKey = @ForeignKey(name = "null"))
	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	@JsonApiToOne
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "task_id",foreignKey = @ForeignKey(name = "null"))
	public Task getTask() {
		return task;
	}

	public void setTask(Task task) {
		this.task = task;
	}

	@JsonApiToOne
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "creater_id",foreignKey = @ForeignKey(name = "null"))
	public User getCreater() {
		return creater;
	}

	public void setCreater(User creater) {
		this.creater = creater;
	}

	@Column(name = "follow_time")
	public Integer getFollowTime() {
		return followTime;
	}

	public void setFollowTime(Integer followTime) {
		this.followTime = followTime;
	}

	@JsonApiToOne
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "header_id",foreignKey = @ForeignKey(name = "null"))
	@JsonApiIncludeByDefault
	@Fetch(FetchMode.JOIN)
	public User getHeader() {
		return header;
	}

	public void setHeader(User header) {
		this.header = header;
	}

	@JsonApiToMany
	@JsonApiIncludeByDefault
	@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@JoinTable(name = "ccd_workorder_concerned", joinColumns = {
			@JoinColumn(name = "workorder_id", nullable = false, updatable = false,foreignKey = @ForeignKey(name = "null")) }, inverseJoinColumns = {
			@JoinColumn(name = "user_id", nullable = false, updatable = false,foreignKey = @ForeignKey(name = "null")) })
	@Fetch(FetchMode.JOIN)
	public Set<User> getConcerned() {
		return concerned;
	}

	public void setConcerned(Set<User> concerned) {
		this.concerned = concerned;
	}

	@Column(name = "tbc_time")
	public Integer getTbcTime() {
		return tbcTime;
	}

	public void setTbcTime(Integer tbcTime) {
		this.tbcTime = tbcTime;
	}

	@Column(name = "complete_time")
	public Integer getCompleteTime() {
		return completeTime;
	}

	public void setCompleteTime(Integer completeTime) {
		this.completeTime = completeTime;
	}

	@Column(name = "create_time")
	public Integer getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Integer createTime) {
		this.createTime = createTime;
	}

	@Column(name = "update_time")
	public Integer getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Integer updateTime) {
		this.updateTime = updateTime;
	}

	@Column(name = "remark")
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}
}
